package view.inventory
{
import flash.display.InteractiveObject;
import flash.display.MovieClip;
import flash.utils.Dictionary;

import framework.core.ComponentBuilder;
import framework.core.TipManager;
import framework.core.UIWidget;

import values.item.IItemValue;

import view.component.tip.EqumentTip;
import view.inventory.menu.InventoryEquipmentItemMenuProxy;
import view.inventory.menu.InventoryFactoryItemMenuProxy;
import view.inventory.menu.InventoryItemMenuProxy;
import view.inventory.menu.InventoryPackItemMenuProxy;
import view.inventory.menu.InventorySkillBookItemMenuProxy;
import view.inventory.tip.InventoryEquipmentItemTip;
import view.inventory.tip.InventoryFactoryItemTip;
import view.inventory.tip.InventoryResourceItemTip;

/**
 * InventoryItemUtil
 * @author jliang
 *
 */
public class InventoryItemUtil
{
	private static const TIP_MAP:Dictionary = new Dictionary(true);
	{
        TIP_MAP["pack"] = InventoryResourceItemTip;
        TIP_MAP["skillbook"] = InventoryResourceItemTip;
		TIP_MAP["resource"] = InventoryResourceItemTip;
		TIP_MAP["equipment"] = EqumentTip;
		TIP_MAP["factory"] = InventoryFactoryItemTip;
	}
		
	private static const MENU_MAP:Dictionary = new Dictionary(true);
	{
        MENU_MAP["pack"] = { skin:"swf.ui.InventoryPackItemMenuSkin", classRef:InventoryPackItemMenuProxy };
        MENU_MAP["skillbook"] = { skin:"swf.ui.InventorySkillBookItemMenuSkin", classRef:InventorySkillBookItemMenuProxy };
		MENU_MAP["resource"] = { skin:"swf.ui.InventoryResourceItemMenuSkin", classRef:InventoryItemMenuProxy };
		MENU_MAP["equipment"] = { skin:"swf.ui.InventoryEquipmentItemMenuSkin", classRef:InventoryEquipmentItemMenuProxy };
		MENU_MAP["factory"] = { skin:"swf.ui.InventoryBuildingItemMenuSkin", classRef:InventoryFactoryItemMenuProxy };
	}
	
	public static function showTip(skin:InteractiveObject, data:IItemValue):void
	{
		TipManager.showTip(skin, data, TIP_MAP[data.template.type]);
	}
	
	public static function showMenu(target:InteractiveObject, data:IItemValue, classDef:Object = null):void
	{
		var def:Object = classDef;
		if (!def)
		{
			def = MENU_MAP[data.template.type];
		}
		
		var skin:MovieClip = UIWidget.createUI(def.skin) as MovieClip;		
		
		var proxy:InventoryItemMenuProxy = ComponentBuilder.create(def.classRef);
		proxy.parse(skin);
		proxy.data = data;
		
		skin.x = target.stage.mouseX - skin.width - 10;
		skin.y = target.stage.mouseY;
		
		target.stage.addChild(skin);
	}
}
}



